package com.framework.middleware.kafka;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.common.TopicPartition;

import java.util.Arrays;
import java.util.Properties;

/**
 * @author chaolong.jin
 * @description
 * @date 2019/08/08 20:44
 */
public class Consumer {
    public static void main(String[] args) {
        Properties props= ClientConnection.loadProp("kafka_consumer.properties");
        KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props);
        TopicPartition topicPartition=new TopicPartition("test",0);
        consumer.assign(Arrays.asList(topicPartition));
        consumer.seek(topicPartition,0);
        while (true) {
            ConsumerRecords<String, String> records = consumer.poll(100);
            for (ConsumerRecord<String, String> record : records){
                System.out.printf("offset = %d, key = %s, value = %s%n", record.offset(), record.key(), record.value());

            }
        }
    }
}
